package com.timoon.webcomponent.utility.navs.stylish;

import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.request.resource.CssResourceReference;
import org.apache.wicket.request.resource.JavaScriptResourceReference;

import com.googlecode.wicket.jquery.ui.JQueryBehavior;
import com.timoon.webcomponent.utility.navs.BaseNavPanel;
import com.timoon.webcomponent.utility.navs.NavParameter;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class StylishNavPanel extends BaseNavPanel {

	private static final long serialVersionUID = 6591696922847839807L;
	private static String SELECTED_KEY="selectedkey";

	public StylishNavPanel(String id, List<NavParameter> navs,PageParameters pp) {
		super(id, navs);
		// TODO Auto-generated constructor stub
		this.add(new StylishJqueryBehavior("#fewfawe"));
		
		final String selectedKey=pp.get(SELECTED_KEY).toString("default");
		
		ListView<NavParameter> listView=new ListView<NavParameter>("wk_li",navs) {
			
			@Override
			protected void populateItem(ListItem<NavParameter> arg0) {
				// TODO Auto-generated method stub
				NavParameter p=arg0.getModelObject();
				
				PageParameters pageParamter=new PageParameters();
				pageParamter.add(SELECTED_KEY, p.getKey());
				
				BookmarkablePageLink link=new BookmarkablePageLink<>("wk_a", p.getTargetPage(),pageParamter);
				arg0.add(link);
				if(selectedKey.equals(p.getKey())){
					link.add(new AttributeModifier("class", "selectedMenu"));
				}
				
				link.add(new Label("wk_span",p.getText()));
			}
		};
		add(listView);
	}

}
class StylishJqueryBehavior extends JQueryBehavior{

	public StylishJqueryBehavior(String selector) {
		super(selector);
		// TODO Auto-generated constructor stub
		this.add(new JavaScriptResourceReference(this.getClass(), "script.js"));
		this.add(new CssResourceReference(this.getClass(), "demo.css"));
	}
	
}
